package org.itboys.mobile.controller.weixin.count;

import org.itboys.admin.entity.lasted.SystemDictionary;
import org.itboys.admin.service.lasted.SystemDictionaryService;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.dto.member.SundayWeixinMemberDto;
import org.itboys.mobile.entity.mongo.SundayAddress;
import org.itboys.mobile.entity.mysql.product.SundayProduct;
import org.itboys.mobile.entity.mysql.score.SundayScore;
import org.itboys.mobile.service.mongo.weixin.address.SundayWeixinAddressService;
import org.itboys.mobile.service.mongo.weixin.count.CooWeixinCountService;
import org.itboys.mobile.service.mysql.weixin.product.SundayWeiXinProductService;
import org.itboys.mobile.util.MemberUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * 作者：zzq
 * 时间：2017/12/7
 * 描述：迈迪龙_微信_结算
 */
@Controller
@RequestMapping("/coo/weixin/count")
public class CooWeixinCountController extends BaseController{
    @Autowired
    private CooWeixinCountService countService;
    @Autowired
    private SundayWeiXinProductService productService;
    @Autowired
    private SundayWeixinAddressService addressService;
    @Autowired
    private SystemDictionaryService dictionaryService;

    @RequestMapping("/index")
    public String index(
            HttpServletRequest request,
            @RequestParam(value = "productId", required = true)Long  productId,
            @RequestParam(value = "addressId", required = false)Long  addressId,
            Model model){
        //获取session中的用户信息
        SundayWeixinMemberDto member = MemberUtil.getUser(request);
        if(LongUtil.isZreo(member.getRecommendId())){
            return "/newcoo/weixin/doLogin";
        }
        SundayAddress address=null;
        if(LongUtil.isNotZreo(addressId)){
            address=addressService.getById(addressId);
        }else {
            address =addressService.getDefaultAddress(member.getId());
        }
        model.addAttribute("address",address);
        SundayProduct product=productService.findOne(productId);
        model.addAttribute("product",product);

        return "/newcoo/weixin/count/index";
    }




}
